/****** Object:  StoredProcedure [dbo].[cms_sp_EntitySearchCmsMediaContent]    Script Date: 25.06.2015 18:07:51 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER procedure [dbo].[cms_sp_EntitySearchCmsMediaContent]
(@SearchQuery varchar(max),
 @IsInAdministrationArea bit = null,
 @SiteGroupId int = null,
 @SiteId int = null
)
AS

declare @Searched table 
(
	MediaContentId int not null	
)

select [MediaContentId] as [Id]
      ,[MediaId]
      ,[SiteId]
      ,[SiteGroupId]
      ,[MetaCode]
      ,[Description]
      ,[CreatedBy]
      ,[DateCreated]
      ,[LastUpdatedBy]
      ,[DateLastUpdated]
      ,[MediaContentName]
  from [dbo].MediaContents M
	 WHERE ((M.SiteGroupId is null and M.SiteId is null) or 
		(M.SiteGroupId = @SiteGroupId and M.SiteId is null) or
		(M.SiteGroupId = @SiteGroupId and M.SiteId = @SiteId)) and 
		M.MediaContentName like '%'+@searchQuery+'%'
GO